<?php

namespace App\Http\Controllers\Frontend;

use App\Exceptions\HttpResponseException;
use App\Traits\WebResponse;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class BaseController extends Controller
{
    use WebResponse;

    /**
     * 服务
     * @var object $service
     */
    protected $service;
    /**
     * 表单新增和删除操作
     * @param array $request_data
     * @param array $success_data
     * @param $method
     * @return JsonResponse
     */
    protected function formSubmission(array $request_data, $method, array $success_data = []) : JsonResponse
    {
        try {
            $method($request_data);
            return $this->success($success_data);

        } catch (HttpResponseException $e) {
            return $this->failed($e->getMessage(), $e->getCode());
        }
    }
}
